package com.qf.demo.votingSystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.demo.votingSystem.entity.CandidateName;
import com.qf.demo.votingSystem.mapper.CandidateNameMapper;
import com.qf.demo.votingSystem.service.ICandidateNameService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Victor
 * @since 2023-02-25
 */
@Service
public class CandidateNameServiceImpl extends ServiceImpl<CandidateNameMapper, CandidateName> implements ICandidateNameService {
    @Override
    public void putVoting(String v_name) throws Exception {
        final CandidateName one = getOne(new QueryWrapper<CandidateName>().eq("v_name", v_name));
        if (one == null){
            throw new Exception("候选人不存在");
        }else {
            final Integer vNum = one.getVNum();
            one.setVNum(vNum+1);
            save(one);
        }


    }
}
